package com.itheima.reggie.dao;

import com.itheima.reggie.entity.Dish;
import com.itheima.reggie.entity.dto.DishDto;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface DishDao {

    @Select("select count(*) from dish where category_id = #{categoryId}")
    Integer findCountByCategoryId(Long categoryId);

    @Insert("insert into dish values(null,#{name},#{categoryId},#{price},#{code},#{image}," +
            "#{description},#{status},#{sort},#{createTime},#{updateTime}," +
            "#{createUser},#{updateUser},0)")
    @Options(useGeneratedKeys = true,keyColumn = "id" ,keyProperty = "id") // useGeneratedKeys = true 插入之后将主键自动封装到当前实体类对象
    void save(DishDto dishDto);

    List<Dish> findByPage(String name);

    @Select("select * from dish where id = #{id}")
    Dish findById(Long id);


    void updateDish(DishDto dishDto);

//    @Select("select * from dish where category_id = #{categoryId}")
    List<Dish> findByCategoryId(@Param("categoryId") Long categoryId,@Param("status") Integer status);

}
